import datetime

from django.db import models

from apps.rbac.models import Menu
from bases.model import APIModel


class Samples(APIModel):
    STATUS = (('O', '开放'), ('R', '生效'), ('C', '关闭'))
    item_no = models.CharField(verbose_name='品番名称', max_length=15, unique=True)
    warehouse = models.CharField(verbose_name='仓库', max_length=15, blank=True, null=True)
    location = models.CharField(verbose_name='库位', max_length=15, blank=True, null=True)
    menu = models.ForeignKey(Menu, verbose_name='菜单', on_delete=models.DO_NOTHING)
    valid_date = models.DateField(verbose_name='生效时间', default=datetime.date.today)
    invalid_date = models.DateField(verbose_name='失效时间')
    status = models.CharField(verbose_name='状态', max_length=1, choices=STATUS)
    note = models.CharField(verbose_name='备注', max_length=500, blank=True, null=True)
    quantity = models.DecimalField(verbose_name='数量', max_digits=18, decimal_places=6, null=True)

    class Meta:
        db_table = 'samples'
        verbose_name = '开发示例'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.item_no
